package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.domain.db.Report;
import com.itheima.mapper.ReportMapper;
import com.itheima.service.db.ReportService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class ReportServiceImpl implements ReportService {
    @Autowired
    private ReportMapper reportMapper;


    @Override
    public Report findByUserIdAndQuestionnaireId(Long userId, String questionnaireId) {
        LambdaQueryWrapper<Report> reportLambdaQueryWrapper = new LambdaQueryWrapper<>();
        reportLambdaQueryWrapper.eq(Report::getUserId,userId).eq(Report::getQuestionnaireId,questionnaireId);
        return  reportMapper.selectOne(reportLambdaQueryWrapper);
    }

    @Override
    public Long save(Report report, Boolean isNew) {
        if(isNew)
        reportMapper.insert(report);
        else
            reportMapper.updateById(report);
        return report.getId();
    }

    @Override
    public Report findById(Long reportId) {
      return  reportMapper.selectById(reportId);
    }

    @Override
    public List<Long> findSimilarYou(Integer score, Long id, String questionnaireId) {

       return reportMapper.similarYou(score, id,questionnaireId);
    }

    @Override
    public Report findByQuestionnaireId(String id) {
        LambdaQueryWrapper<Report> reportLambdaQueryWrapper = new LambdaQueryWrapper<>();
        reportLambdaQueryWrapper.eq(Report::getQuestionnaireId,id);
        return reportMapper.selectOne(reportLambdaQueryWrapper);
    }


}
